<template>
	<div id='login'>
		<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
			<el-form-item label="用户账号" prop="account">
				<el-input v-model="ruleForm.account"></el-input>
			</el-form-item>
			<el-form-item label="用户密码" prop="password">
				<el-input v-model="ruleForm.password" type="password"></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
				<el-button @click="resetForm('ruleForm')">重置</el-button>
			</el-form-item>
		</el-form>
	</div>
</template>
<script scoped>
	export default {
		name: 'login',
		data() {
			return {
				ruleForm: {
					account: '',
					password: ''
				},
				rules: {
					account: [{
							required: true,
							message: '请输入账号',
							trigger: 'blur'
						},
						{
							min: 3,
							max: 11,
							message: '长度在 3 到 11 个字符',
							trigger: 'blur'
						}
					],
					password: [{
						required: true,
						message: '请输入密码',
						trigger: 'blur'
					}]
				}
			};
		},
		methods: {
			submitForm(formName) {
				this.$refs[formName].validate((valid) => {
					if (valid) {
						this.$axios.post("/getUser", this.ruleForm).then(res => {
							var user = res.data;
							if (user== null ||user=='') {
								this.$message("登录失败");
								return;
							}
							sessionStorage.setItem("userId", user.userId);
							sessionStorage.setItem("userName", user.username);
							this.$axios.get("/getMenuButton?uid="+user.userId+"&jpid=0")
							.then(msg =>{
								var str = JSON.stringify(msg.data)
								sessionStorage.setItem("Jurisdictions",str);
							});
							this.$router.push("/home/insured");
						})
					} else {
						return false;
					}
				});
			},
			resetForm(formName) {
				this.$refs[formName].resetFields();
			}
		}
	}
</script>

<style scoped>
	.el-form {
		width: 500px;
		margin: 0 auto;
	}
</style>
